//替换所有问号
class Solution {
public:
    string modifyString(string s) 
    {
        if(s.size()==1 && s[0]=='?')
        {
            s[0]='a';
            return s;
        }
        else if(s[0]=='?')
        {
            char ch='a';
            s[0]=s[1]=='a'?'b':'a';
        }
        if(s[s.size()-1]=='?')
        {
            char ch='a';
            s[s.size()-1]=s[s.size()-2]=='a'?'b':'a';
        }
        for(int i=1;i<s.size()-1;i++)
        {
            char ch='a';
            if(s[i]=='?')
            {
                while(s[i-1]==ch || s[i+1]==ch) ch++;
                s[i]=ch;
            }
        }
        return s;
    }
};
//提莫攻击
class Solution {
public:
    int findPoisonedDuration(vector<int>& timeSeries, int duration) 
    {
        //计算 这次和下一次间隔 即可得到本次中毒持续多少秒
        //间隔大于持续时间则 res+=d
        //间隔小于持续时间则 res+= time[i+1]-time
        int res=0;
        for(int i=0;i<timeSeries.size()-1;i++)
        {
            int x=timeSeries[i+1]-timeSeries[i];
            if(x>duration) res+=duration;
            else res+=x;
        }
        res+=duration;
        return res;
    }
};
//N 字形变换

class Solution {
public:
    string convert(string s, int numRows) 
    {
        if(numRows==1) return s;
        int d=2 * numRows -2;
        int n=s.size();
        string res="";
        for(int i=0;i<n;i+=d) res +=s[i];
        for(int k=1;k<numRows-1;k++)
        {
            for(int i=k,j=d-k;i<n || j<n;i+=d,j+=d)
            {
                if(i<n) res+=s[i];
                if(j<n) res+=s[j];
            }
        }
        for(int i=numRows-1;i<n;i+=d)
        {
            res+=s[i];
        }
        return res;
    }
};